<template>
  <nav class="nav">
    <router-link :to="getUrl(item)" v-for="item in listData" :key="item.name">{{
      item.name
    }}</router-link>
  </nav>
</template>

<script>
export default {
  computed: {
    listData() {
      let arr = [];
      arr.push({ level: 1, name: "首页" });
      if (this.$route.params.t_cat_pk != 5) {
        arr.push({
          level: 2,
          name: this.$route.params.cat_name,
          t_cat_pk: this.$route.params.t_cat_pk,
        });
      }
      // 如果有板块，添加板块
      if (this.$route.params.plant_name) {
        arr.push({
          level: 3,
          name: this.$route.params.plant_name,
          ...this.$route.params,
        });
      }
      return arr;
    },
  },
  methods: {
    getUrl(item) {
      // 去往二级页面首页
      if (item.level == 2) {
        return {
          name: "second-center",
          params: { cat_name: item.name, t_cat_pk: item.t_cat_pk },
        };
      // 去往板块列表
      } else if (item.level == 3) {
        return this.getListUrl({ cat_name: item.cat_name, t_cat_pk: item.t_cat_pk }, item);
      } else {
        return "/";
      }
    },
  },
};
</script>

<style scoped>
.nav {
  padding-bottom: 10px;
}

.nav > a:nth-child(n + 2)::before {
  content: ">";
  margin: 0px 10px;
}
</style>